<?php
class Password extends PageBaseUpdate {

	public function InitializeComponent(){
		parent::InitializeComponent();
		$this->ClassName = "Usuario";
	}

	public function onLoad($param){
		parent::onLoad($param);
		if(!$this->IsPostBack){
			$this->setBackPage();
			$id=$this->getIdUser();
			$oUsuario= UsuarioPeer::retrieveByPK($id);
			if(is_object($oUsuario)){
				$Rol= $oUsuario->getIdrol();
				if($Rol==4){//Rol de Asociado
					$this->Master->menucontainer->Visible = false;
					$this->btnResetPassword->Visible = false;
				}
			}
			if($id!=0){
				$oUsuario = UsuarioPeer::retrieveByPK($id);
				$this->lblUsuario->Text = $oUsuario->getUsername();
				$this->lblData->Text =$oUsuario->getNombrecompleto();
			}

		}
	}

	public function getIdUser(){
		$id=0;
		if($this->Request["id"]!=""){
			$id =$this->Request["id"];
		}else
			{
			if(!is_null($_SESSION["IdUsuario"]))
				{
					$id = $_SESSION["IdUsuario"];
				}
			}
		return $id;
	}

	public function setBackPage()
	{
		$origen = $_SERVER['HTTP_REFERER'];
		$aOrigen = split("\?", $origen);
		$_SESSION["backpage"] = "?".$aOrigen[1];
	}

	protected function btnAceptar_OnClick(){
		if($this->IsValid){
			$id=$this->getIdUser();
			if($id!=0){
				$oUsuario = UsuarioPeer::retrieveByPK($id);
				$oUsuario->setPassword($this->txtContrasena->Text);
				$oUsuario->save();
			}
			$backpage=$_SESSION["backpage"];
			unset($_SESSION["backpage"]);
			$this->Back($backpage);
			session_destroy();
		}
	}

	protected function btnResetPassword_OnClick(){
		if($this->IsValid){
			$id=$this->getIdUser();
			if($id!=0){
				$oUsuario = UsuarioPeer::retrieveByPK($id);
				$oUsuario->setPassword("Abcd1234");
				$oUsuario->save();
			}
			$backpage=$_SESSION["backpage"];
			unset($_SESSION["backpage"]);
			$this->Back($backpage);
			session_destroy();
		}
	}

	public function btnCancelar_OnClick($sender, $param)
    {
		$backpage=$_SESSION["backpage"];
		unset($_SESSION["backpage"]);
		$this->Back($backpage);
		session_destroy();
    }
}
?>